<template>
  <!-- 登陆页 -->
  <div>
    <van-form @submit="onSubmit">
      <van-nav-bar
        title="登陆"
        left-text="返回"
        left-arrow
        @click-left="goBack"
      />
      <van-field
        v-model="name"
        name="name"
        label="用户名"
        placeholder="用户名"
        required
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="pwd"
        type="password"
        name="pwd"
        label="密码"
        placeholder="密码"
        required
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import {login} from "../../apis/login"
export default {
  data() {
    return {
      name: "",
      pwd: "",
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    async onSubmit({name,pwd}) {
      // console.log(values);
      let res = await this.$http.request({
        url:login,
        method:"POST",
        data:{
          name,
          pwd
        }
      })
      console.log(res)
      if(res.data.code===1000){
        this.$toast.success(res.data.msg)
        this.$setStorage("jwtToken",res.data.token)
        this.$router.push("/user")
      }
    },
  },
};
</script>

<style>
</style>